package com.zero.business.bicycle.controller;


import com.zero.business.bicycle.service.BicycleService;
import com.zero.common.domain.Page;
import com.zero.common.domain.Result;
import com.zero.domain.Bicycle;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;

@RestController
@RequestMapping("bicycle")
public class BicycleController {

    @Resource
    private BicycleService bicycleService;

    /*
    *   分页展示所有未被使用的单车    status=0
    * */
    @GetMapping("getBicycle")
    public Result getBicycle(){

        Page<Bicycle> page = bicycleService.getBicycle();

        return new Result(200,"查询成功",page);

    }


    /*
    *   根据 bicycleId 获取车辆数据         被 订单模块 远程调用 的接口
    * */
    @GetMapping("selectByPrimaryKey")
    public Bicycle selectByPrimaryKey(Integer bicycleId){

        return bicycleService.selectByPrimaryKey(bicycleId);

    }


    /*
     *   1.更新车辆状态为 使用中 的状态  statue=1        被 订单模块 远程调用 的接口
     *   2.更新车辆状态为 未使用 的状态  statue=0        被 订单模块 远程调用 的接口
     * */
    @PutMapping("updateByPrimaryKeySelective")
    public void updateByPrimaryKeySelective(Integer bicycleId, String status, String remark){
        // 创建单车对象，设置 bicycleId 和 status
        Bicycle bicycle = Bicycle.builder()
                .bicycleId(bicycleId)
                .status(Integer.parseInt(status))     // 状态
                .updateBy("admin")
                .updateTime(new Date())
                .remark(remark)
                .build();

        // 更新
        bicycleService.updateByPrimaryKeySelective(bicycle);

    }



}
